package org.moore.controller;

import org.moore.model.Map;
import org.moore.utils.Countdown;
import org.moore.utils.Data;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

// 游戏暂停类
public class PauseButtonListener implements MouseListener {
    @Override
    public void mouseClicked(MouseEvent e) {
        if (Map.isMapType() == 2){
            try {
                Countdown.pause();
            } catch (NullPointerException ex) {
                JOptionPane.showMessageDialog(null,"游戏还未开始，无法暂停！");
                return;
            }
        } else if (Map.isMapType() == 1){
            if (Data.COUNT == 0){
                JOptionPane.showMessageDialog(null,"游戏还未开始，无法暂停！");
                return;
            }
        }
        int result = JOptionPane.showConfirmDialog(null, "游戏暂停，是否继续？", "游戏暂停", JOptionPane.YES_NO_OPTION);
        if (result == JOptionPane.YES_OPTION) {
            // 当用户点击确定按钮时，继续游戏
            if (Map.isMapType() == 2){
                Countdown.resume();
            }
        }
    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
